<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>
<?php use_javascript('jquery.ui.core.js')?>
<?php use_javascript('jquery.ui.datepicker.js')?>
<?php use_javascript('date.js')?>
<?php use_stylesheet('jquery-ui-1.8.1.custom.css')?>
<?php use_javascript('jquery.calculation.js')?>


<form action="<?php echo url_for('compras/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<?php endif; ?>

  <div id="formulario">
  <table width="100%" style="text-align: center;">
    
    <tbody>
      <?php echo $form->renderGlobalErrors() ?>
      <tr>
        <th><?php echo $form['estado']?><?php echo $form['cuenta_id']->renderLabel() ?></th>
        <th><?php echo $form['nombre_encargado']->renderLabel() ?></th>
        <th><?php echo $form['correo_encargado']->renderLabel() ?></th>
        <th><?php echo $form['anexo_encargado']->renderLabel() ?></th>
      </tr>
      <tr>
        <td><?php echo $form['cuenta_id']->renderError() ?><?php echo $form['cuenta_id'] ?></td>
        <td><?php echo $form['nombre_encargado']->renderError() ?> <?php echo $form['nombre_encargado'] ?></td>
        <td><?php echo $form['correo_encargado']->renderError() ?> <?php echo $form['correo_encargado'] ?></td>
        <td><?php echo $form['anexo_encargado']->renderError() ?> <?php echo $form['anexo_encargado'] ?></td>
      </tr>

      <tr
     	<th><?php echo $form['proveedor_id']->renderLabel() ?></th>	
     	<th><?php echo $form['nombre_contacto']->renderLabel() ?></th>
        <th><?php echo $form['correo_contacto']->renderLabel() ?></th>
		<th><?php echo $form['telefono_contacto']->renderLabel() ?></th>
	  </tr>
	  
	  <tr>
	    <td><?php echo $form['proveedor_id']->renderError() ?> <?php echo $form['proveedor_id'] ?></td>
	    <td><?php echo $form['nombre_contacto']->renderError() ?> <?php echo $form['nombre_contacto'] ?></td>
        <td><?php echo $form['correo_contacto']->renderError() ?> <?php echo $form['correo_contacto'] ?></td>
	    <td><?php echo $form['telefono_contacto']->renderError() ?> <?php echo $form['telefono_contacto'] ?></td>
	  </tr>
	  
	  <tr>
		<th><?php echo $form['forma_pago']->renderLabel() ?></th>
        <th><?php 
					if($sf_user->hasCredential('Abastecimiento')):
						echo $form['plazo_entrega']->renderLabel();
					endif	
					?></th>
		<th></th>
		<th></th>
	  </tr>
	  
	  <tr>
	    <td>
	    
	    <?php echo $form['forma_pago']->renderError() ?>
	    <?php echo $form['forma_pago'] ?>
	    
	    </td>
        <td>
        <?php if($sf_user->hasCredential('Abastecimiento')):?>
        <?php echo $form['plazo_entrega']->renderError() ?> <?php echo $form['plazo_entrega'] ?>
        <?php endif ?>
        </td>
	    <td></td>
        <td></td>
	  </tr>
	  <?php if($sf_user->hasCredential('Finanzas')||$sf_user->hasCredential('Abastecimiento')):?>
	  <tr>
		<th colspan="4"><?php echo $form['observacion']->renderLabel() ?></th>
		</tr>
		<tr>
			<td colspan="4">
			<?php echo $form['observacion']->renderError() ?> <?php echo $form['observacion'] ?>
			</td>
		</tr>
	  <?php endif ?>
    </tbody>
  </table>
  
  
 
  <table id="contenedor">
    <thead>
       <tr>
      <th>Art&iacute;culo</th>
      <th>Cantidad</th>
      <th>Valor Unitario Neto</th>
      <th>Subtotal</th>
      <th>Observación</th>
    </tr>
    </thead>
	 <tbody>
  <?php foreach ($form['ItemCompraNacional'] as $item):?>
    <tr>
      <td><?php echo $item['articulo_id'] ?></td>
      <td><?php echo $item['cantidad'] ?></td>
      <td><?php echo $item['costo_neto_unitario'] ?></td>
      <td><?php echo $item['subtotal'] ?></td>
      <td><?php echo $item['observacion']->render() ?></td>
    </tr>
    <?php endforeach ?>
  </tbody>
  
  </table>
  
  <table width="100%">
  <tbody>
    <tr >
      <td width="20%"></td>
      <td width="20%"></td>
      <td width="20%"></td>
      <td width="20%"> Valor Total Neto: </td>
      <td width="20%"> <?php echo $form['neto']->renderError() ?> <?php echo $form['neto'] ?> </td>
    </tr>
    
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td> Iva (19%):  </td>
      <td> <?php echo $form['iva']->renderError() ?> <?php echo $form['iva'] ?> </td>
    </tr>
    
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td> Valor Total:  </td>
      <td> <?php echo $form['total'] ?> </td>
    </tr>
  </tbody>
</table>
  
   <table width="100%">
    <tfoot>
      <tr>
        <td colspan="2">
          <?php echo $form->renderHiddenFields(false) ?>
			<?php echo button_to('Volver', 'compras/index') ?>
          	<?php if (!$form->getObject()->isNew()): ?>
          		<?php echo link_to('<button>Borrar</button>', 'compras/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => '¿Está seguro de eliminar?')) ?>
          	<?php endif; ?>
          <input type="submit" value="Guardar" />
        </td>
      </tr>
    </tfoot>
  </table> 
  
   
</div>

